Skip to content

Added note about copying elements during conversion #1643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2020
Merged

Added note about copying elements during conversion #1643

merged 4 commits into from
May 6, 2020

Conversation

magnolia-k
Copy link
Contributor

scala/bug#11872

In addition, the method introduction was modified to the latest method list.

magnolia added 2 commits February 16, 2020 16:52
@@ -22,7 +22,7 @@ Collection classes that implement `Iterable` just need to define this method; al

* **Addition**, `concat`, which appends two collections together, or appends all elements of an iterator to a collection.
* **Map** operations `map`, `flatMap`, and `collect`, which produce a new collection by applying some function to collection elements.
* **Conversions** `toArray`, `toList`, `toIterable`, `toSeq`, `toIndexedSeq`, `toStream`, `toSet`, `toMap`, which turn an `Iterable` collection into something more specific. All these conversions return their receiver argument unchanged if the run-time type of the collection already matches the demanded collection type. For instance, applying `toList` to a list will yield the list itself.
* **Conversions** `to`, `toList`, `toVector`, `toMap`, `toSet`, `toSeq`, `toIndexedSeq`, `toBuffer`, `toArray` which turn an `Iterable` collection into something more specific. If the destination is a mutable collection(to(collection.mutable.X), to(collection.X), toArray, toBuffer), a new collection is created by copying the original elements. All these conversions return their receiver argument unchanged if the run-time type of the collection already matches the demanded collection type. For instance, applying `toList` to a list will yield the list itself.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like some missing backquotes here, to make to(collection.mutable.X) and so forth render in monospace font

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!
fixed it.

@SethTisue
Copy link
Member

If the destination is a mutable collection(to(collection.mutable.X), to(collection.X)`

I'm wondering about the presence of to(collection.X) here. Those collections aren't necessarily mutable. Is it actually true that copying always occurs? Maybe it is, but it would surprise me.

And regardless, it doesn't seem correct to me for the phrasing to imply that collection.X is mutable, since it might or might not be.

@SethTisue
Copy link
Member

interested in getting this across the finish line?

@SethTisue
Copy link
Member

@magnolia-k interested in getting this across the finish line?

@magnolia-k
Copy link
Contributor Author

@SethTisue

I'm sorry it took me so long to reply.

It's true, as you point out, not all of the to(collection.X) generates a copy.

@SethTisue SethTisue merged commit e5a6cbf into scala:master May 6, 2020
@SethTisue
Copy link
Member

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants